package com.jiang.demo.service;

import com.jiang.demo.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ApiService {

    @Async
    public void exec() {
        log.info("异步执行~~~~~~~~~~~~~~~~start");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info("异步执行~~~~~~~~~~~~~~~~end");
    }


    @Cacheable(cacheNames = "user", keyGenerator = "cacheKeyGenerator")
    public UserEntity getUser(Long id){
        UserEntity user = UserEntity.builder().id(id).name("jiang"+id).build();
        log.info("[get user select ~]");
        return user;
    }

}
